package com.yufubao.service.service.applet.product.impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yufubao.framework.result.PageUtils;
import com.yufubao.framework.util.page.Query;
import com.yufubao.model.pojo.applet.product.SupplierApplyFailLogEntity;
import com.yufubao.service.mapper.applet.product.SupplierApplyFailLogDao;
import com.yufubao.service.service.applet.product.SupplierApplyFailLogService;
import org.springframework.stereotype.Service;

import java.util.Map;

import static com.yufubao.framework.util.MapParamsUtil.getKey;


@Service("supplierApplyFailLogService")
public class SupplierApplyFailLogServiceImpl extends ServiceImpl<SupplierApplyFailLogDao, SupplierApplyFailLogEntity> implements SupplierApplyFailLogService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<SupplierApplyFailLogEntity> page = this.page(
                new Query<SupplierApplyFailLogEntity>().getPage(params),
                new QueryWrapper<SupplierApplyFailLogEntity>()
        );

        return new PageUtils(page);
    }

    @Override
    public PageUtils searchAllStatusInfo(Map<String, Object> params) {


        //法人/店铺名称/手机号码
        String key = getKey(params);

        LambdaQueryWrapper<SupplierApplyFailLogEntity> wrapper = Wrappers.<SupplierApplyFailLogEntity>lambdaQuery()
                .like(StrUtil.isNotBlank(key), SupplierApplyFailLogEntity::getLegalPerson, key)
                .or().like(StrUtil.isNotBlank(key), SupplierApplyFailLogEntity::getStoreName, key)
                .or().eq(StrUtil.isNotBlank(key), SupplierApplyFailLogEntity::getMobile, key);

        IPage<SupplierApplyFailLogEntity> page = this.page(
                new Query<SupplierApplyFailLogEntity>().getPage(params),
                wrapper
        );

        return new PageUtils(page);
    }

}